﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;
using System.Data.Linq;

namespace DomainModel.Entities
{
    // This is the Linq to SQL class for the Educations table.
    // This is the bottom layer of the DAL.
    [Table(Name = "Educations")]
    public class Education : IDataErrorInfo
    {
        [Column(Name = "educationID", IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
        public int EducationID { get; set; }

        [Column(Name = "applicationID")]
        public int ApplicationID { get; set; }

        [Column(Name = "school_name")]
        public string SchoolName { get; set; }
        [Column(Name = "school_address")]
        public string SchoolAddress { get; set; }
        [Column(Name = "year_start")]
        public int YearStart { get; set; }
        [Column(Name = "year_end")]
        public int YearEnd { get; set; }
        [Column(Name = "year_graduated")]
        public int YearGraduated { get; set; }
        [Column(Name = "degree")]
        public string Degree { get; set; }

        public string this[string fieldName]
        {
            get
            {
                if (((fieldName == "SchoolName") && string.IsNullOrEmpty(SchoolName)) ||
                    ((fieldName == "SchoolName") && (SchoolName.Length > 25)))
                    return "School name must not be empty or longer than 25 characters.";
                if (((fieldName == "SchoolAddress") && string.IsNullOrEmpty(SchoolAddress)) ||
                    ((fieldName == "SchoolAddress") && (SchoolAddress.Length > 50)))
                    return "School address must not be empty or longer than 50 characters.";
                if (((fieldName == "Degree") && string.IsNullOrEmpty(Degree)) ||
                    ((fieldName == "Degree") && (Degree.Length > 25)))
                    return "Degree must not be empty or longer than 25 characters.";
                if ((fieldName == "YearStart") && (YearStart < 0))
                    return "Year start must be greater than 0.";
                if ((fieldName == "YearEnd") && (YearEnd < 0))
                    return "Year end must be greater than 0.";
                if ((fieldName == "YearGraduated") && (YearGraduated < 0))
                    return "Year graduated must be greater than 0.";

                return null;
            }
        }

        public string Error { get { return null; } }
    }
}